
#ifndef _MEMBER_BENTRY_H_
#define _MEMBER_BENTRY_H_

#include <BImage>
#include <BDate>
#include <BTime>
#include <BEntry>

#ifdef linux
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <dirent.h>
#endif

#ifdef _WIN32
#include <Windows.h>
#undef min
#undef max
#endif

#define entry_member(entry)		((member_BEntry*)((BEntry*)entry)->_ptr)

namespace BWE
{
#ifdef _WIN32
	inline Attrib ConvertToAttrib(DWORD dwFileAttributes)
	{
		Attrib attribs = Attrib_File;
		if (dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			attribs = Attrib_Folder;
		if (dwFileAttributes & FILE_ATTRIBUTE_READONLY)
			attribs |= Attrib_ReadOnly;
		if (dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)
			attribs |= Attrib_Hidden;
		//if (dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)
		//	attribs |= Attrib_File;
		//if (dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)
		//	attribs |= Attrib_File;
		if (dwFileAttributes & FILE_ATTRIBUTE_DEVICE)
			attribs |= Attrib_Drive;
		//if (dwFileAttributes & FILE_ATTRIBUTE_NORMAL)
		//	attribs |= Attrib_File;
		//if (dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY)
		//	attribs |= Attrib_File;
		//if (dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE)
		//	attribs |= Attrib_File;
		if (dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT)
			attribs |= Attrib_Link;
		//if (dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED)
		//	attribs |= Attrib_File;
		//if (dwFileAttributes & FILE_ATTRIBUTE_OFFLINE)
		//	attribs |= Attrib_File;
		//if (dwFileAttributes & FILE_ATTRIBUTE_NOT_CONTENT_INDEXED)
		//	attribs |= Attrib_File;
		//if (dwFileAttributes & FILE_ATTRIBUTE_ENCRYPTED)
		//	attribs |= Attrib_File;
		//if (dwFileAttributes & FILE_ATTRIBUTE_INTEGRITY_STREAM)
		//	attribs |= Attrib_File;
		//if (dwFileAttributes & FILE_ATTRIBUTE_VIRTUAL)
		//	attribs |= Attrib_File;
		//if (dwFileAttributes & FILE_ATTRIBUTE_NO_SCRUB_DATA)
		//	attribs |= Attrib_File;
		return attribs;
	}
	inline DWORD ConvertFromAttrib(Attrib attribs)
	{
		DWORD dwFileAttributes = 0;
		if (attribs & Attrib_File)
			dwFileAttributes |= FILE_ATTRIBUTE_NORMAL;
		if (attribs & Attrib_Folder)
			dwFileAttributes |= FILE_ATTRIBUTE_DIRECTORY;
		if (attribs & Attrib_ReadOnly)
			dwFileAttributes |= FILE_ATTRIBUTE_READONLY;
		if (attribs & Attrib_Hidden)
			dwFileAttributes |= FILE_ATTRIBUTE_HIDDEN;
		if (attribs & Attrib_Drive)
			dwFileAttributes |= FILE_ATTRIBUTE_DEVICE;
		if (attribs & Attrib_Link)
			dwFileAttributes |= FILE_ATTRIBUTE_REPARSE_POINT;
		return dwFileAttributes;
	}
#endif

#ifdef linux
	inline Attrib ConvertToAttrib(mode_t mode)
	{
		Attrib attribs = Attrib_None;
		if (S_ISREG(mode))
			attribs |= Attrib_File;
		if (S_ISDIR(mode))
			attribs |= Attrib_Folder;
		if (S_ISCHR(mode))
			attribs |= Attrib_Char;
		if (S_ISBLK(mode))
			attribs |= Attrib_File;
		if (S_ISFIFO(mode))
			attribs |= Attrib_Pipe;
		if (S_ISLNK(mode))
			attribs |= Attrib_Link;
		if (S_ISSOCK(mode))
			attribs |= Attrib_Socket;
		return attribs;
	}
	inline mode_t ConvertFromAttrib(Attrib attribs)
	{
		mode_t mode = 0;
		if (attribs & Attrib_File)
			S_ISREG(mode);
		if (attribs & Attrib_Folder)
			S_ISDIR(mode);
		if (attribs & Attrib_ReadOnly)
			S_ISDIR(mode);
		if (attribs & Attrib_Hidden)
			S_ISDIR(mode);
		if (attribs & Attrib_Drive)
			S_ISDIR(mode);
		if (attribs & Attrib_Link)
			S_ISLNK(mode);
		return attribs;
	}
#endif

	class member_BEntry
	{
	public:
		member_BEntry(BEntry* entry);
		~member_BEntry();

		BEntry*			boss;
		Attrib			attrib;
		BString			path;
		BDate			date;
		BTime			time;
		BLong			size;

	};
}

#endif
